package com.example.websocketdemo.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.messaging.simp.config.MessageBrokerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
import org.springframework.web.socket.config.annotation.AbstractWebSocketMessageBrokerConfigurer;
import org.springframework.web.socket.config.annotation.EnableWebSocketMessageBroker;
import org.springframework.web.socket.config.annotation.StompEndpointRegistry;
import org.springframework.web.socket.config.annotation.WebSocketMessageBrokerConfigurer;

/**
 * @author ljw
 * @description
 * @date 2021/12/9 7:18
 */
@Configuration
@EnableWebSocketMessageBroker //开启使用 Stomp 协议来传输基于代理的消息
public class WebSocketConfig implements  WebSocketMessageBrokerConfigurer {
    /**
     * 注册 STOMP 协议的节点（endpoint）,并指定URL
     * @param
     * @author ljw
     * @date 2021/12/9 7:24
     */
    @Override
    public void registerStompEndpoints(StompEndpointRegistry registry) {
        //指定 URL
        registry.addEndpoint("/endpointWisely")
                //指定使用 SockJS协议
                .withSockJS();
    }

    /**
     * 配置消息代理
     * @param 
     * @author ljw
     * @date 2021/12/9 7:30 
     */
    @Override
    public void configureMessageBroker(MessageBrokerRegistry registry) {
        registry.enableSimpleBroker("/topic");
    }
}
